package com.qfedu.knowledge.entity.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * @ClassName SourceEnums
 * @Author ykx
 * @Date 2024/1/15 17:25
 * @Version 1.0
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum SourceEnum {
    STAND(1, "一站到底"),
    ;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 异常消息
     */
    private String value;

    /**
     * 根据枚举值找值
     *
     * @param code 枚举值
     * @return value
     */
    public static String getValueByCode(Integer code) {
        for (SourceEnum ele : SourceEnum.values()) {
            if (Objects.equals(ele.getCode(), code)) {
                return ele.getValue();
            }
        }
        return "";
    }

    /**
     * 根据值找枚举值
     *
     * @param value 值
     * @return value
     */
    public static Integer getCodeByValue(String value) {
        for (SourceEnum ele : SourceEnum.values()) {
            if (Objects.equals(ele.getValue(), value)) {
                return ele.getCode();
            }
        }
        return 0;
    }
}
